package com.sky.mapper;

import com.sky.entity.Address;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author 褚金龙
 * @Date 2024/9/27 20:02
 */
@Mapper
public interface AddressMapper {
    /**
     * 添加收货地址
     * @param address
     */

    public void saveAddress(Address address) ;

    /**
     * 查询所有收货地址
     * @return
     */
    @Select("select *from address_book ")
    List<Address> addressList();

    /**
     * 根据id查询地址
     * @param id
     * @return
     */
    @Select("select *from address_book where id=#{id} and user_id=#{userId}")
    Address getById(Long id,Long userId);

    /**
     * 修改收货地址
     * @param address
     */
    void updateAddress(Address address);

    /**
     * 根据id和用户id删除收货地址
     * @param id
     * @param userId
     */
    @Delete("delete from address_book where id=#{id} and user_id=#{userId}")
    void deleteAddress(Long id, Long userId);


    /**
     * 把所有地址修改默认收货地址
     * @param address
     *
     */
    @Update("update address_book set is_default=#{isDefault} where  user_id=#{userId}")
    void defaultAddress(Address address);

    /**
     * 查询默认地址
     * @param isDefault
     * @param userId
     * @return
     */
    @Select("select *from address_book where is_default=#{isDefault} and user_id=#{userId}")
    List<Address> getDefaultAddress(Integer isDefault, Long userId);
}
